<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src='${ctxPath}/assets/mui/js/jquery-1.11.3.js'></script>
	</head>
	<style>
		p{
			font-size: 12px;
			margin: 0;
		}
		.button{
			background-color: #A6A6A6; color: black; /* Green */
		    border: none;
		    color: white;
		    padding: 10px 32px;
		    text-align: center;
		    text-decoration: none;
		    display: inline-block;
		    font-size: 14px;
    	}
		#order-title{
			margin-top:30px;
		}
	</style>

	<body>
		<div style="width: 10% ; float: left;">
			<button style="background: #1b8d4f" id="button" class="button" onclick="doPrint()">打印</button>
		</div>
		<div style="width: 10% ; float: left;">
			<button style="background: #217ab9" id="button2" class="button" onclick="doPrint2();">确定</button>
		</div>
		<div style="width:10% ; float: left;">
			<button style="background: #bb0d0d" id="button3" class="button" onclick="doPrint3()">取消</button>
		</div>
		<div id="big" style="page-break-after: always;width: 100%;height: 100%; ">
		</div>
		<div style="page-break-after: always;"></div>

		<script type="text/jscript">
			//通过URL 获取参数
			function GetQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) return unescape(r[2]);
				return null;
			};
			var now = new Date()
			var year = now.getFullYear()
			var month = now.getMonth()+1
			var day = now.getDate()
			var hour = now.getHours()
			var m = now.getMinutes()
			var s = now.getSeconds()
			var newdate = year+"-"+month+"-"+day+" "+hour+":"+m+":"+s
			function findtou(){
				return '<div id="-title" style="width: 100%; height:40px;margin-top: 10px;">'+
					'<p style="float: left; width: 100%;height: 2px;text-align: center;font-size: 18px;font-weight: 600;">发车出库明细</p>'+
				'</div>';
			}
			load();
			var cnt = 0;
			function load(){
				var big = $("#big");
				//big.append(storageOutmsg);
				$.ajax({
					url:'${ctxPath}/tDispatch/getPrintStorageOut',
				    type:'post',
				    dataType:'json',
				    data:{"dispatchNumber":GetQueryString("dispatchNumber"),"getLocationId":GetQueryString("getLocationid")},
				    success:function(data){
				        if(data!=null){
							var storageOuttitle = '<div id="order-title1" style="width: 100%;margin-top: 40px;">'+
														'<div id="order-title-1" style="width: 100%;">'+
															'<p style="float: left; width: 25%;">发货方：'+data.setUnit+'</p>'+
															'<p style="float: left; width: 30%;">收货门店：'+data.getUnit+'</p>'+
															'<p style="float: left; width: 20%;">门店电话：'+data.getTel+'</p>'+
															'<p style="float: left; width: 25%;">发货日期：'+GetQueryString("startDate")+'</p>'+
														'</div>'+
															'<div id="order-title-1" style="width: 100%;">'+
															'<p style="float: left; width: 55%;">地址：'+data.getLocation+'</p>'+
															'<p style="float: left; width: 20%;">整件：'+data.zjsum+'</p>'+
															'<p style="float: left; width: 25%;">拆零：'+data.clsum+'</p>'+
														'</div>'+
													'</div>';

							var storageOutbottom = '<div id="order-title" style="width: 100%;">'+
														'<div id="order-title-1" style="width: 100%;">'+
															'<p style="float: left; width: 30%;height: 30px;">车牌号：____________</p>'+
															'<p style="float: left; width: 30%;height:30px;">司机：____________</p>'+
															'<p style="float: right; width: 40%;height: 30px;">联系方式:____________</p>'+

														'</div>'+
													'</div>'+
													'<div id="order-title" style="width: 100%;height: 30px;">'+
													'<div id="order-title-1" style="width: 100%;height: 30px;">'+
														'<p style="float: left; width: 30%;height: 30px;">收货日期：____________</p>'+
														'<p style="float: left; width: 30%;height: 30px;">收货门店签字：____________</p>'+
														'<p style="float: left; width: 100%;height: 30px;">订单号：____________</p>'+
														'<p style="float: left; width: 30%;height: 30px;">打印人：'+data.printName+'</p>'+
														'<p style="float: right; width: 40%;height: 30px;">打印时间：'+newdate+'</p>'+
													'</div>'+
												'</div>';
							$.ajax({
								url:'${ctxPath}/tDispatch/getOutDetailed',
								type:'post',
								dataType:'json',
								async:false,
								data:{"dispatchNumber":GetQueryString("dispatchNumber"),"getLocationId":GetQueryString("getLocationid")},
								success:function(data1){
									if(data1.length>0){
                                        $.each(data1,function(key,value){
                                        	cnt++;
                                            var storageOutdata = '<div id="order-date" style="width: 100%;">'+
                                                            '<table id="order-table" style="width: 100%; font-size: 12px;" border="1px solid" cellpadding="0" cellspacing="0">'+
                                                                '<thead>'+
                                                                    '<th>出库单号</th>'+
                                                                    '<th colspan="2">'+value.orderOutNumber+'</th>'+
                                                                    '<th>订单备注</th>'+
                                                                    '<th colspan="6">'+value.notes+'</th>'+
                                                                '</thead>'+
                                                                '<thead>'+
                                                                    '<th>序号</th>'+
                                                                    '<th>商品编号</th>'+
                                                                    '<th>商品名称</th>'+
                                                                    '<th>规格</th>'+
                                                                    '<th>单位</th>'+
                                                                    '<th>数量</th>'+
                                                                    '<th>单价</th>'+
                                                                    '<th>金额</th>'+
                                                                    '<th>明细备注</th>'+
                                                                    '<th>仓库</th>'+
                                                                '</thead>'+
                                                                '<tbody>';
                                            var ncont = 0.0;
                                            var nSum = 0.0;
                                            $.each(value.itemList,function(key1,value1){
                                                ncont += value1.psNum*1;
                                                nSum +=  value1.outMoney*1;
                                                storageOutdata += '<tr>'+
                                                                        '<td>'+(key1+1)+'</td>'+
                                                                        '<td>'+value1.goodsNumber+'</td>'+
                                                                        '<td>'+value1.goodsName+'</td>'+
                                                                        '<td>'+value1.goodsSpecs+'</td>'+
                                                                        '<td>'+value1.unit+'</td>'+
                                                                        '<td>'+value1.psNum+'</td>'+
                                                                        '<td>'+value1.goodsPrice+'</td>'+
                                                                        '<td>'+value1.outMoney+'</td>'+
                                                                        '<td>'+value1.notes+'</td>'+
                                                                        '<td>'+value1.getUnit+'</td>'+
                                                                    '</tr>';
                                            });
                                            storageOutdata += '<tr>'+
                                                                    '<td></td>'+
                                                                    '<td></td>'+
                                                                    '<td></td>'+
                                                                    '<td></td>'+
                                                                    '<td>数量合计：</td>'+
                                                                    '<td>'+Math.round(ncont * 100) / 100+'</td>'+
                                                                    '<td></td>'+
                                                                    '<td>'+Math.round(nSum * 100) / 100+'</td>'+
                                                                    '<td></td>'+
                                                                    '<td></td>'+
                                                                '</tr>';

                                            storageOutdata += '</tbody>'+
                                                        '</table>'+
                                                    '</div>';
                                            var tou = findtou()
                                            if(cnt > 1){
                                            	big.append('<div style="page-break-after: always;"></div>' + tou+storageOuttitle+storageOutdata+storageOutbottom);
                                            }else{
                                            	big.append(tou+storageOuttitle+storageOutdata+storageOutbottom);
                                            }

                                        });
									}else{
										alert("未查询到发货单明细!");
									}
								},
								error:function(data){
									alert("查询发货单明细异常!");
								}
							});
						}else{
							alert("未查询到发货单!");
						}
				    },
				    error: function(data){
						alert("查询发货单异常!");
				    }
				});
			};
			//打印
			function doPrint() {
		        bdhtml = window.document.body.innerHTML;
		        phtnl = window.document.getElementById("big").innerHTML;
		        window.document.body.innerHTML = phtnl; //把需要打印的指定内容赋给big
		        window.print(); //调用浏览器的打印功能打印指定区域
		        window.document.body.innerHTML=bdhtml; // 最后还原页面

		    };
		    //打印的回调
		    var beforePrint = function() {
		        //打印前调用
		    };
		    var afterPrint = function() {
		        //打印后调用
<!--            	var Indexs = parent.layer.getFrameIndex(window.name);-->
<!--                parent.layer.close(Indexs);-->
				doPrint2();
		    };
		    if (window.matchMedia) {
		        var mediaQueryList = window.matchMedia('print');
		        mediaQueryList.addListener(function(mql) {
		            if (mql.matches) {
		                beforePrint();
		            } else {
		                afterPrint();
		            }
		        });
		    }
		 function doPrint3(){
        var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    }

    function doPrint2(){
        $.ajax({
            type: 'get',
            url: "/tDispatch/getPrintStorageOut2",
            data:{"dispatchNumber":GetQueryString("dispatchNumber"),"getLocationid":GetQueryString("getLocationid")},
            async: false,
            dataType:"json",
            success: function (data) {
                parent.submit = 1
                var Index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(Index);
            }
        })
    }
		</script>
	</body>
</html>